package com.hexinfo.dmpro.monitor.service.serviceparam;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hexinfo.dmpro.common.base.BaseService;
import com.hexinfo.dmpro.common.base.Page;
import com.hexinfo.dmpro.common.base.PageResult;
import com.hexinfo.dmpro.monitor.dao.serviceparam.CmServiceParamDao;
import com.hexinfo.dmpro.monitor.dao.serviceparam.CmTargetParamDao;
import com.hexinfo.dmpro.monitor.model.serviceparam.CmAlarmCountModel;
import com.hexinfo.dmpro.monitor.model.serviceparam.CmParamWarnModel;
import com.hexinfo.dmpro.monitor.model.serviceparam.CmServiceParamReq;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.*;

@Service
@Slf4j
public class CmServiceParamService extends BaseService {

    @Autowired
    private CmServiceParamDao cmServiceParamDao;
    @Autowired
    private CmTargetParamDao cmTargetParamDao;

    /**
     * 参数详情 首页列表 参数告警信息查询
     *
     * @param page
     * @param req
     * @return
     */
    public PageResult selParamWarn(Page page, CmServiceParamReq req) {
        List<CmAlarmCountModel> cmAlarmCountModels = cmTargetParamDao.selAlarmCount(req);
        PageResult selParamWarn = selectPage(cmServiceParamDao, "selParamWarn", page, req);
        List<CmParamWarnModel> cmParamWarnModelList = (List<CmParamWarnModel>)selParamWarn.getContent();
        for(CmParamWarnModel cmParamWarnModel : cmParamWarnModelList){
            for(CmAlarmCountModel cmAlarmCountModel : cmAlarmCountModels){
                if(cmParamWarnModel.getCmFlag().equals(cmAlarmCountModel.getCmFlag())
                && cmParamWarnModel.getClusterFlag().equals(cmAlarmCountModel.getClusterFlag())){
                    cmParamWarnModel.setTotalNum(cmAlarmCountModel.getTotalNum());
                    cmParamWarnModel.setDealNum(cmAlarmCountModel.getDealNum());
                    cmParamWarnModel.setNoDealNum(cmAlarmCountModel.getTotalNum() - cmAlarmCountModel.getDealNum());
                    break;
                }
            }
        }
        return selParamWarn;
    }
}
